      
      MODULE MPI_VARIABLES
!-----Variables for MPI-------------------------------------------------------------------
      include 'mpif.h' 

!      use MPI

      ! Parameters
      integer(4), parameter :: abssuv_indic = 1
      integer(4), parameter :: arrgatherwri_indic = 2
      integer(4), parameter :: bcast_3darr_profile_indic = 3
      integer(4), parameter :: bcast_scavar_indic = 4
      integer(4), parameter :: global_sum_2darr_indic = 5
      integer(4), parameter :: global_summod_2darr_indic = 6
      integer(4), parameter :: global_sumsquar_2darr_indic = 7
      integer(4), parameter :: arr3dexch_indic = 8
      integer(4), parameter :: arr2dexch_indic = 9
      integer(4), parameter :: transpose_xy_yz_indic = 10
      integer(4), parameter :: transpose_xz_xy_indic = 11
      integer(4), parameter :: transpose_yz_xz_indic = 12
      integer(4), parameter :: transpose_xy_y_indic = 13
      integer(4), parameter :: transpose_y_x_indic = 14
      integer(4), parameter :: transpose_x_xy_indic = 15
      integer(4), parameter :: bcast_array_indic = 16

      integer(4), parameter :: decomp = 1

      integer(4) :: ierr_MPI
      integer(4) :: rank_MPI
      integer(4) :: rank_comm3d
      integer(4) :: rank_comm3d_000, rank_comm3d_110
      integer(4) :: size_MPI
      integer(4) :: len_MPI
      integer(4) :: rankn
      integer(4) :: bcast_rank
      integer(4) :: rankout
      integer(4) :: rankhor000
      integer(4) :: rankhor111 
      integer(4) :: root_reduce ! The ROOT process for MPI_REDUCE
      integer(4) :: nprocx
      integer(4) :: nprocy
      integer(4) :: nprocs
      integer(4) :: status_MPI(MPI_STATUS_SIZE)
!      integer(4), allocatable, dimension(:,:) :: nbx_MPI, nby_MPI           
      integer(4) :: dims(1:3)
      integer(4) :: coords(1:3)
      integer(4) :: coordn(1:3)
      integer(4) :: prplc(1:26) = 0
      integer(4) :: dims2d(1:2)
      integer(4) :: coords2d(1:2)
      integer(4) :: prplcxy(1:8) = 0
      integer(4) :: ndim = 3
      integer(4) :: tag
      integer(4) :: comm3d
      integer(4) :: comm2dx
      integer(4) :: comm2dy
      integer(4) :: comm2ds
      integer(4) :: commhoris
      integer(4) :: comm_xbound(1:2), comm_ybound(1:2)
      integer(4) :: group_comm3d
      integer(4) :: group_horis
      integer(4) :: group_xbound(1:2), group_ybound(1:2)
      integer(4) :: identif
      integer(4) :: nxi, nxe
      integer(4) :: nyi, nye
      integer(4) :: nsi, nse
      integer(4) :: nxsi, nxse
      integer(4) :: nysi, nyse
      integer(4) :: nssi, nsse
      integer(4) :: nx0i, nx1e
      integer(4) :: ny0i, ny1e
      integer(4) :: ns0i, ns1e
      integer(4) :: nx2e, ny2e
      integer(4) :: nxs2i, nxs2e
      integer(4) :: nys2i, nys2e
      integer(4) :: nss2i, nss2e
      integer(4) :: nx0si, nx1se
      integer(4) :: ny0si, ny1se
      integer(4) :: ns0si, ns1se
      integer(4) :: nx0i_x, nx1e_x
      integer(4) :: ny0i_y, ny1e_y
      integer(4) :: ix_mid, iy_mid
      integer(4) :: nxsh, nysh, nssh
      integer(4) :: nxsh2, nysh2, nssh2
      integer(4), parameter :: maxshift = 2
      integer(4) :: ns0i_xproc, ns1e_xproc
      integer(4) :: ns0i_yproc, ns1e_yproc
      integer(4), allocatable :: nxpi(:), nxpe(:), &
      & nypi(:), nype(:), nspi(:), nspe(:)
      integer(4), allocatable :: nxpi_ys(:), nxpe_ys(:), &
      & nypi_ys(:), nype_ys(:), nspi_ys(:), nspe_ys(:)
      integer(4), allocatable :: nxpi_xs(:), nxpe_xs(:), &
      & nypi_xs(:), nype_xs(:), nspi_xs(:), nspe_xs(:)
      integer(4), allocatable :: ksize(:), isize(:), jsize(:)
      integer(4), allocatable :: nxpi_x(:), nxpe_x(:), &
      & nypi_y(:), nype_y(:)

      integer(4), allocatable :: sigmasize(:)
      integer(4) :: req2(1:1000)
      integer(4) :: req(1:52,1:2000)
      integer(4) :: request_send_2d(1:8) = MPI_REQUEST_NULL
      integer(4) :: request_recv_2d(1:8) = MPI_REQUEST_NULL
      integer(4) :: request_send_3d(1:maxshift,1:26) = MPI_REQUEST_NULL
      integer(4) :: request_recv_3d(1:maxshift,1:26) = MPI_REQUEST_NULL
      character(len=100) :: proc_name
      character(len=100), allocatable :: proc_name_all(:)
      logical :: isperiodic(1:3)
      logical :: isperiodic2d(1:2)
      logical :: reorder
      logical :: horisbound
      logical :: lowbound
      logical :: upperbound
      logical :: xbound, xlbound, xrbound
      logical :: ybound, ylbound, yrbound
      logical :: parallel
      data isperiodic(1:3), reorder /.false.,.false.,.false.,.true./
      data isperiodic2d(1:2) /.false.,.false./
      data nxsh,nysh,nssh /1,1,1/
      data nxsh2,nysh2,nssh2 /2,2,2/
      data root_reduce /0/

      SAVE
                                                                    
      END MODULE MPI_VARIABLES

